package xyz.jpcr.covid19app.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Text;

import java.util.ArrayList;

import xyz.jpcr.covid19app.Model.RumorResult.Rumor;
import xyz.jpcr.covid19app.Model.RumorResult.RumorResult;
import xyz.jpcr.covid19app.R;

public class RumorAdapter extends RecyclerView.Adapter<RumorAdapter.ViewHolder> {
    private Context mContext;
    private ArrayList<Rumor> rumorArrayList;

    public RumorAdapter(Context mContext, ArrayList<Rumor> rumorArrayList) {
        this.mContext = mContext;
        this.rumorArrayList = rumorArrayList;
    }

    @NonNull
    @NotNull
    @Override
    public RumorAdapter.ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.activity_rumor_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull RumorAdapter.ViewHolder holder, int position) {
        holder.title_tv.setText(rumorArrayList.get(position).getTitle());
        holder.body_tv.setText(rumorArrayList.get(position).getBody());
        holder.mainSummary_tv.setText(rumorArrayList.get(position).getMainSummary());
    }

    @Override
    public int getItemCount() {
        return rumorArrayList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView title_tv, mainSummary_tv, body_tv;
        public ViewHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            title_tv = itemView.findViewById(R.id.title_tv);
            mainSummary_tv = itemView.findViewById(R.id.mainSummary_tv);
            body_tv = itemView.findViewById(R.id.body_tv);
        }
    }
}
